#ifndef GPU_MEMORY_MANAGER_H
#define GPU_MEMORY_MANAGER_H

#include <set>

class GpuMemoryManager
{
public:
	struct MemoryChunk
	{
		void* p;
		unsigned int size;
		bool free;
	};
	struct MemoryChunkSizeComp {
		bool operator() (MemoryChunk* lhs, MemoryChunk* rhs) const
		{return lhs->size < rhs->size;}
	};

	static GpuMemoryManager* getInstance();

	virtual ~GpuMemoryManager();

	void init();
	void destroy();

	MemoryChunk* getChunk(unsigned int size);
	void releaseChunk(MemoryChunk* memory);

protected:
	static GpuMemoryManager* instance;
	GpuMemoryManager();

	MemoryChunk* addNewChunk(unsigned int size);

	std::multiset<MemoryChunk*, MemoryChunkSizeComp> memorySet;
};

#endif